import os
import time

from apscheduler.schedulers.blocking import BlockingScheduler

scheduler = BlockingScheduler()
BASE_DIR = '/root/data/merge_img'
EXPIRE = 1200


def rm_expired_img():
    """ 清理过期图片 """
    now = time.time()
    for item in os.listdir(BASE_DIR):
        path = os.path.join(BASE_DIR, item)
        if os.path.isfile(path):
            if now - os.path.getmtime(path) > EXPIRE:
                os.remove(path)
    return


scheduler.add_job(rm_expired_img, 'interval', seconds=EXPIRE)
scheduler.start()
